# 作者: 赵炳森
# 2025年11月03日22时24分39秒
# 2215031808@qq.com
def open_r():
    file = open('file2.txt', mode='r', encoding='utf-8')
    text = file.read()
    print(text)
    file.write('world')
    file.close()


def open_rw():
    file = open('file2.txt', mode='r+', encoding='utf-8')
    text = file.read()
    print(text)
    file.write('world')
    file.close()


def open_w():
    file = open('file3', mode='w', encoding='utf-8')
    file.write('world坚持学习')
    file.close()


def open_a():
    file = open('file1', mode='a', encoding='utf-8')
    file.write('how')
    file.close


def use_readline():
    file = open("file2.txt", encoding='utf-8')
    while True:
        # 读取一行内容
        text = file.readline()
        # 判断是否读到内容
        if not text:
            break
        # 每读取一行的末尾已经有了一个 `\n`
        print(text, end="")
    # 关闭文件
    file.close()


if __name__ == '__main__':
    # open_r()
    # open_rw()
    # open_w()
    # open_a()
    use_readline()
